//
//  YZProvinceTableViewCell.m
//  kuaiyi
//
//  Created by Yip-Jun on 16/5/6.
//
//

#import "YZProvinceTableViewCell.h"
#import "YZSaveDataTool.h"
#import "Masonry.h"

@interface YZProvinceTableViewCell ()

@property (nonatomic, strong) UIButton *selectButton;

@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation YZProvinceTableViewCell

+ (instancetype)provinceTableViewCell {
    YZProvinceTableViewCell *cell = [[YZProvinceTableViewCell alloc] init];
    
    [cell prepareUI];

    return cell;
}

- (void)setProvince:(YZProvinces *)province {
    _province = province;
    self.nameLabel.text = self.province.name;
}

- (void)prepareUI {
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.selectButton];
}

- (void)layoutSubviews {
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.trailing.equalTo(self.contentView).offset(-16);
    }];
    
    [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(16);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}

- (void)setIsSelect:(BOOL)isSelect {
    _isSelect = isSelect;
    self.selectButton.selected = isSelect;
    [YZSaveDataTool setBool:self.isSelect forKey:self.province.name];
}

- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [[UIButton alloc] init];
        [_selectButton setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState: UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState: UIControlStateSelected];
    }
    return _selectButton;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
//        _nameLabel.text = self.province.name;
    }
    return _nameLabel;
}

@end
